package com.mogu.user.controller;


import com.mogu.entity.TUser;
import com.mogu.user.pojo.Email;
import com.mogu.user.pojo.MyBlog;
import com.mogu.user.pojo.MyComment;
import com.mogu.user.service.EmailService;
import com.mogu.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    EmailService emailService;

    @Autowired
    UserService userService;

    @GetMapping("/sendEmail")
    public String sendEmail(@RequestBody Email email){
        return emailService.send(email);
    }

//    @PostMapping("/regist")
//    public String regist(@RequestBody TUser tUser){
//
//        return userService.regist(tUser);
//    }

    @GetMapping("/setEmail")
    public String setAndSend(@RequestBody Map<String,String> map){

        return userService.sends(map);
    }

    @PostMapping("/login")
    public String login(@RequestBody TUser tUser){
        return userService.login(tUser);
    }

    @GetMapping("/message/{username}")
    public TUser selectOne(@PathVariable("username") String username){
        return userService.selectOne(username);
    }


    @PostMapping("/edit")
    public String editUser(@RequestBody TUser tUser){
        System.out.println(tUser);
        return userService.edit(tUser);

    }


    /**
     * 通过uid查询我的博客
     * @param uid
     * @return
     */
    @GetMapping("/findMyBlogByUid/{uid}")
    public List<MyBlog> findMyBlogByUid(@PathVariable String uid){

        return this.userService.findMyBlogByUid(uid);
    }


    /**
     * 通过uid查询我的评论
     * @param uid
     * @return
     */
    @GetMapping("/findMyCommentByUid/{uid}")
    public List<MyComment> findMyCommentByUid(@PathVariable String uid){
        return this.userService.findMyCommentByUid(uid);
    }
}
